package com.weiqiao.mall.rest;

import com.weiqiao.mall.domain.TeamEntity;
import com.weiqiao.mall.service.ITeamService;
import com.weiqiao.mall.service.vo.TeamVO;
import com.weiqiao.utils.PageUtil;
import com.weiqiao.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class TeamController {


    @Autowired
    private ITeamService teamService;

    @GetMapping("/team-list")
    public ResponseEntity teamList(TeamVO vo) {
        List<TeamEntity> list = teamService.teamList(vo);
        int total = teamService.countTeam(vo);
        return new ResponseEntity(PageUtil.toPage(list, total), HttpStatus.OK);
    }

    /**
     * 获取当前团队详情
     * @return
     */
    @GetMapping("/get-team-info/{team_id}")
    public ResponseEntity getTeamInfo(@PathVariable String team_id) {
        int companyId = SecurityUtils.getCompanyId();
        TeamEntity entity = teamService.getTeamInfo(companyId, team_id);
        return new ResponseEntity(entity, HttpStatus.OK);
    }

    @PostMapping("/update-team")
    public ResponseEntity updateTeam(TeamVO vo) {
        return new ResponseEntity(teamService.updateTeam(vo), HttpStatus.OK);
    }

    @PostMapping("/insert-team")
    public ResponseEntity insertTeam(TeamVO vo) {
        return new ResponseEntity(teamService.insertTeam(vo), HttpStatus.OK);
    }

    @PostMapping("/delete-team")
    public ResponseEntity deleteTeam(TeamVO vo) {
        return new ResponseEntity(teamService.deleteTeam(vo), HttpStatus.OK);
    }

    @PostMapping("/not-leader-list")
    public ResponseEntity notLeaderList(TeamVO vo) {
        return new ResponseEntity(teamService.notLeaderList(vo), HttpStatus.OK);
    }


}
